package com.woohua.thread.countdownlatch;

import java.util.concurrent.CountDownLatch;

/***
 * @title EatingActivity
 * @description
 * @author woo hua
 * @version 1.0.0
 * @create 2023/3/17 14:13
 **/
public class EatingActivity implements Runnable {

    private CountDownLatch countDownLatch;

    public EatingActivity(CountDownLatch countDownLatch) {
        this.countDownLatch = countDownLatch;
    }


    @Override
    public void run() {
        try {
            //等待吃饭
            System.out.println("Waiting for dinner...");
            this.countDownLatch.await();

            // 所有事情做完后，await 被唤醒，开始吃饭
            System.out.println("Starting eating...");
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}
